<template>
    <div>
        <HomePageHead></HomePageHead>
        <HomePageNavigation></HomePageNavigation>
        <HomeSecondaryHeading :titleData="pageData" :pinyinid="routeId"></HomeSecondaryHeading>
        <!-- 频道页 -->
        <main class="index_main">
            <section class="channel_1 clearfix">
                <div class="channel_1_box clearfix">
                    <div class="roll_1_box clearfix">
                        <HomeSwiperNzgx :imgData="pageData[0].data"></HomeSwiperNzgx>
                    </div>
                </div>
                <div class="channel_2_box clearfix">
                    <div class="channel_ul_1 clearfix">
                        <NuxtLink class="channel_ul_1_a dot1"
                            :href="getLinkPathDetail(item)"
                            :title="item.title"
                            v-for="item in pageData[0].data2"
                            :key="item.id"
                            :target="item.islink == 1 ? '_blank' : '_self'"
                        >
                            {{ item.title }}
                        </NuxtLink>
                    </div>
                </div>
            </section>
            <!-- 广告 1-->
            <HomeAdvertising :imgurl="adImg1"></HomeAdvertising>
            <section class="channel_2 clearfix">
                <div class="channel_1_box">
                    <div class="channel_head_box clearfix">
                        <div class="channel_head_box_left">
                            <div class="channel_head_left_a_btn">
                                <NuxtLink 
                                    class="channel_head_left_a channel_head_left_a_only" 
                                    :href="getLinkPath(pageData[1])" 
                                    v-if="pageData[1]" 
                                    :title="pageData[1].alias"
                                >
                                    {{ pageData[1].alias }}
                                </NuxtLink>
                            </div>
                        </div>
                    </div>
                    <!--热点话题 open-->
                    <div class=" clearfix">
                        <div class="channel_3_box clearfix">
                            <div class="channel_ul_2 clearfix">
                                <NuxtLink class="channel_ul_2_a dot1"
                                    :href="getLinkPathDetail(item)"
                                    :title="item.title"
                                    v-for="item in pageData[1].data3"
                                    :key="item.id"
                                    :target="item.islink == 1 ? '_blank' : '_self'"
                                >
                                    {{ item.title }}
                                </NuxtLink>
                            </div>
                        </div>
                        <div class="channel_4_box clearfix">
                            <div class="channel_img_ul_1">
                                <div class="channel_img_ul_1_li">
                                    <NuxtLink class="channel_img_ul_1_li_a"
                                        :href="getLinkPathDetail(item)"
                                        :title="item.title"
                                        v-for="item in pageData[1].data"
                                        :key="item.id"
                                        :target="item.islink == 1 ? '_blank' : '_self'"
                                    >
                                        <img class="channel_img_ul_1_li_img" :src="item.imgurl" alt="item.imgurl">
                                        <div class="channel_img_ul_1_li_dot2 dot2">
                                            {{item.title}}
                                        </div>
                                    </NuxtLink>
                                </div>
                            </div>
                            <div class="channel_img_ul_even_1 clearfix">
                                <div class="channel_img_ul_even_1_li" v-for="item in pageData[1].data2">
                                    <NuxtLink class="channel_img_ul_even_1_li_a"
                                        :href="getLinkPathDetail(item)"
                                        :title="item.title"
                                        :key="item.id"
                                        :target="item.islink == 1 ? '_blank' : '_self'"
                                    >
                                        <img class="channel_img_ul_even_1_li_img" :src="item.imgurl" alt="item.imgurl">
                                        <div class="channel_img_ul_even_1_li_dot2 dot2">
                                            {{item.title}}
                                        </div>
                                    </NuxtLink>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!--热点话题 end-->
                </div>
                <div class="channel_2_box">
                    <div class="channel_head_box clearfix">
                        <div class="channel_head_box_left">
                            <div class="channel_head_left_a_btn">
                                <NuxtLink class="channel_head_left_a channel_head_left_a_only" 
                                    :href="getLinkPath(pageData[2])" 
                                    v-if="pageData[2]" 
                                    :title="pageData[2].alias"
                                >
                                    {{ pageData[2].alias }}
                                </NuxtLink>
                            </div>
                        </div>
                        <div class="channel_head_box_right">
                            <NuxtLink class="channel_head_box_right_1_a" 
                                :href="getLinkPath(pageData[2])" 
                                v-if="pageData[2]" 
                                :title="pageData[2].alias"
                            >
                                栏目简介
                            </NuxtLink>
                        </div>
                    </div>
                    <!--人物访谈 open-->
                    <div class=" clearfix">
                        <div class="channel_even_img_ul_2 clearfix">
                            <div class="channel_even_img_ul_2_li" v-for="item in pageData[2].data">
                                <NuxtLink class="channel_even_img_ul_2_a"
                                    :href="getLinkPathDetail(item)"
                                    :title="item.title"
                                    :key="item.id"
                                    :target="item.islink == 1 ? '_blank' : '_self'"
                                >
                                    <img class="channel_even_img_ul_2_li_img" :src="item.imgurl" alt="item.title">
                                    <div class="channel_even_img_ul_2_dot1 dot1">{{ item.title }}</div>
                                </NuxtLink>
                            </div>
                        </div>
                        <div class="channel_ul_3 clearfix">
                            <NuxtLink class="channel_ul_3_a dot1"
                                :href="getLinkPathDetail(item)"
                                :title="item.title"
                                v-for="item in pageData[2].data2"
                                :key="item.id"
                                :target="item.islink == 1 ? '_blank' : '_self'"
                            >
                                {{ item.title }}
                            </NuxtLink>
                        </div>
                    </div>
                    <!--人物访谈 end-->
                </div>
            </section>
            <section class="channel_3 clearfix">
                <div class="channel_1_box">
                    <div class="channel_head_box clearfix">
                        <div class="channel_head_box_left">
                            <div class="channel_head_left_a_btn">
                                <NuxtLink class="channel_head_left_a channel_head_left_a_only" 
                                    :href="getLinkPath(pageData[3])" 
                                    v-if="pageData[3]" 
                                    :title="pageData[3].alias"
                                >
                                    {{ pageData[3].alias }}
                                </NuxtLink>
                            </div>
                        </div>
                        <div class="channel_head_box_right">
                            <NuxtLink class="channel_head_box_right_1_a" 
                                :href="getLinkPath(pageData[3])" 
                                v-if="pageData[3]" 
                                :title="pageData[3].alias"
                            >
                                栏目简介
                            </NuxtLink>
                        </div>
                    </div>
                    <!--国际采风 open-->
                    <div class=" clearfix">
                        <div class="channel_ul_4 clearfix">
                            <NuxtLink class="channel_ul_4_a dot1"
                                :href="getLinkPathDetail(item)"
                                :title="item.title"
                                v-for="item in pageData[3].data2"
                                :key="item.id"
                                :target="item.islink == 1 ? '_blank' : '_self'"
                            >
                                {{ item.title }}
                            </NuxtLink>
                        </div>
                    </div>
                    <!--国际采风 end-->
                </div>
                <div class="channel_2_box">
                    <div class="channel_head_box clearfix">
                        <div class="channel_head_box_left">
                            <div class="channel_head_left_a_btn">
                                <NuxtLink class="channel_head_left_a channel_head_left_a_only" 
                                    :href="getLinkPath(pageData[4])" 
                                    v-if="pageData[4]" 
                                    :title="pageData[4].alias"
                                >
                                    {{ pageData[4].alias }}
                                </NuxtLink>
                            </div>
                        </div>
                        <div class="channel_head_box_right">
                            <NuxtLink class="channel_head_box_right_1_a" 
                                :href="getLinkPath(pageData[4])" 
                                v-if="pageData[4]" 
                                :title="pageData[4].alias"
                            >
                                栏目简介
                            </NuxtLink>
                        </div>
                    </div>
                    <!--品牌快讯 open-->
                    <div class="channel_img_ul_2">
                        <div class="channel_img_ul_2_li">
                            <NuxtLink class="channel_img_ul_2_li_a"
                                :href="getLinkPathDetail(item)"
                                :title="item.title"
                                v-for="item in pageData[4].data"
                                :key="item.id"
                                :target="item.islink == 1 ? '_blank' : '_self'"
                            >
                                <img class="channel_img_ul_2_li_img" :src="item.imgurl" alt="item.imgurl">
                                <div class="channel_img_ul_2_li_dot2 dot2">{{item.title}}</div>
                            </NuxtLink>
                        </div>
                    </div>
                    <!--品牌快讯 end-->
                </div>
            </section>
            <!-- 广告 2-->
            <HomeAdvertising :imgurl="adImg2"></HomeAdvertising>
            <section class="channel_4 clearfix">
                <div class="channel_1_box">
                    <div class="channel_head_box clearfix">
                        <div class="channel_head_box_left">
                            <div class="channel_head_left_a_btn">
                                <NuxtLink class="channel_head_left_a channel_head_left_a_only" 
                                    :href="getLinkPath(pageData[5])" 
                                    v-if="pageData[5]" 
                                    :title="pageData[5].alias"
                                >
                                    {{ pageData[5].alias }}
                                </NuxtLink>
                            </div>
                        </div>
                        <div class="channel_head_box_right">
                            <NuxtLink class="channel_head_box_right_1_a" 
                                :href="getLinkPath(pageData[5])" 
                                v-if="pageData[5]" 
                                :title="pageData[5].alias"
                            >
                                栏目简介
                            </NuxtLink>
                        </div>
                    </div>
                    <!--企业采风 open-->
                    <div class=" clearfix">
                        <div class="channel_3_box clearfix">
                            <div class="channel_img_ul_3_ul">
                                <div class="channel_img_ul_3_li">
                                    <NuxtLink class="channel_img_ul_3_li_a"
                                        :href="getLinkPathDetail(item)"
                                        :title="item.title"
                                        v-for="item in pageData[5].data"
                                        :key="item.id"
                                        :target="item.islink == 1 ? '_blank' : '_self'"
                                    >
                                        <img class="channel_img_ul_3_li_img" :src="item.imgurl" alt="item.title">
                                        <div class="channel_img_ul_3_li_dot1 dot1">
                                            {{ item.title }}
                                        </div>
                                    </NuxtLink>
                                </div>
                            </div>
                        </div>
                        <div class="channel_4_box clearfix">
                            <div class="channel_ul_5 clearfix">
                                <NuxtLink class="channel_ul_5_a dot1"
                                    :href="getLinkPathDetail(item)"
                                    :title="item.title"
                                    v-for="item in pageData[5].data2"
                                    :key="item.id"
                                    :target="item.islink == 1 ? '_blank' : '_self'"
                                >
                                    {{ item.title }}
                                </NuxtLink>
                            </div>
                        </div>
                    </div>
                    <!--企业采风 end-->
                    <div class="channel_head_box clearfix channel_head_box_2">
                        <div class="channel_head_box_left">
                            <div class="channel_head_left_a_btn">
                                <NuxtLink class="channel_head_left_a channel_head_left_a_only" 
                                    :href="getLinkPath(pageData[6])" 
                                    v-if="pageData[6]" 
                                    :title="pageData[6].alias"
                                >
                                    {{ pageData[6].alias }}
                                </NuxtLink> 
                            </div>
                        </div>
                        <div class="channel_head_box_right">
                            <NuxtLink class="channel_head_box_right_1_a" 
                                :href="getLinkPath(pageData[6])" 
                                v-if="pageData[6]" 
                                :title="pageData[6].alias"
                            >
                                栏目简介
                            </NuxtLink> 
                        </div>
                    </div>
                    <!--农资动态 open-->
                    <div class=" clearfix">
                        <div class="channel_3_box clearfix">
                            <div class="channel_img_ul_4_ul">
                                <div class="channel_img_ul_4_li">
                                    <NuxtLink class="channel_img_ul_4_li_a"
                                        :href="getLinkPathDetail(item)"
                                        :title="item.title"
                                        v-for="item in pageData[6].data"
                                        :key="item.id"
                                        :target="item.islink == 1 ? '_blank' : '_self'"
                                    >
                                        <img class="channel_img_ul_4_li_img" :src="item.imgurl" alt="item.title">
                                        <div class="channel_img_ul_4_li_dot1 dot1">
                                            {{ item.title }}
                                        </div>
                                    </NuxtLink>
                                </div>
                            </div>
                        </div>
                        <div class="channel_4_box clearfix">
                            <div class="channel_ul_6 clearfix">

                                <NuxtLink class="channel_ul_6_a dot1"
                                    :href="getLinkPathDetail(item)"
                                    :title="item.title"
                                    v-for="item in pageData[6].data2"
                                    :key="item.id"
                                    :target="item.islink == 1 ? '_blank' : '_self'"
                                >
                                    {{ item.title }}
                                </NuxtLink>
                            </div>
                        </div>
                    </div>
                    <!--农资动态 end-->
                </div>
                <div class="channel_2_box">
                    <div class="channel_head_box clearfix">
                        <div class="channel_head_box_left">
                            <div class="channel_head_left_a_btn">
                                <NuxtLink class="channel_head_left_a channel_head_left_a_only" 
                                    :href="getLinkPath(pageData[7])" 
                                    v-if="pageData[7]" 
                                    :title="pageData[7].alias"
                                >
                                    {{ pageData[7].alias }}
                                </NuxtLink> 
                            </div>
                        </div>
                        <div class="channel_head_box_right">
                            <NuxtLink class="channel_head_box_right_1_a" 
                                :href="getLinkPath(pageData[7])" 
                                v-if="pageData[7]" 
                                :title="pageData[7].alias"
                            >
                                栏目简介
                            </NuxtLink> 
                        </div>
                    </div>
                    <!--专题报道 open-->
                    <div class=" clearfix">
                        <div class="channel_img_ul_5_ul">
                            <div class="channel_img_ul_5_li">
                                <NuxtLink class="channel_img_ul_5_li_a"
                                    :href="getLinkPathDetail(item)"
                                    :title="item.title"
                                    v-for="item in pageData[7].data"
                                    :key="item.id"
                                    :target="item.islink == 1 ? '_blank' : '_self'"
                                >
                                    <img class="channel_img_ul_5_li_img" :src="item.imgurl" alt="item.title">
                                    <div class="channel_img_ul_5_li_dot1 dot1">{{item.title}}</div>
                                </NuxtLink>
                            </div>
                        </div>
                        <div class="index_ul_7 clearfix">
                            <NuxtLink class="index_ul_7_a dot1"
                                :href="getLinkPathDetail(item)"
                                :title="item.title"
                                v-for="item in pageData[7].data2"
                                :key="item.id"
                                :target="item.islink == 1 ? '_blank' : '_self'"
                            >
                                {{item.title}}
                            </NuxtLink>
                        </div>
                    </div>
                    <!--专题报道 end-->
                </div>
            </section>
        </main>
        <!-- 页脚部分 -->
        <HomeFoot1></HomeFoot1>
    </div>
</template>

<script setup>
//0.加载页面依赖 start ---------------------------------------->
import { ref, onMounted } from 'vue';
import { ElMessage } from 'element-plus';
//0.加载页面依赖 end ---------------------------------------->

//1.获得路由id start ---------------------------------------->
const targetSegment = getRoutePath(1);
//1.1 获得当前的路由id
let routeId;
//通过导航路径反向查询导航id
const getRouteId = await requestDataPromise('/web/getWebsiteRoute', {
    method: 'GET',
    query: {
        'pinyin': targetSegment,
    },
});
if (getRouteId.code == 200) {
    routeId = getRouteId.data.category_id
} else {
    console.log("获得路由id出错！", getRouteId.message)
}
//1.获得路由id end ---------------------------------------->

//2.选项卡 start ---------------------------------------->
let showTabs = ref(1)
let qhtabs = function (number) {
    console.log(number)
    showTabs.value = number
}
//2.选项卡 end ---------------------------------------->

//3.广告 start ---------------------------------------->
let adImg1 = ref({})
let adImg2 = ref({})
let adImg3 = ref({})
let adImg4 = ref({})
onMounted(async () => {
    //从客户端获取行政职能部门 加快打开速度
    const { $webUrl, $CwebUrl } = useNuxtApp();
    //广告1
    let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=snzxw_category_0001`
    const responseAd1 = await fetch(url, {
        headers: {
            'Content-Type': 'application/json',
            'Userurl': $CwebUrl,
            'Origin': $CwebUrl
        }
    });
    const resultAd1 = await responseAd1.json();
    adImg1.value = resultAd1.data[0];

    //广告2
    let url2 = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=snzxw_category_0002`
    const responseAd2 = await fetch(url2, {
        headers: {
            'Content-Type': 'application/json',
            'Userurl': $CwebUrl,
            'Origin': $CwebUrl
        }
    });
    const resultAd2 = await responseAd2.json();
    adImg2.value = resultAd2.data[0];

    //广告3
    let url3 = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=snzxw_category_0003`
    const responseAd3 = await fetch(url3, {
        headers: {
            'Content-Type': 'application/json',
            'Userurl': $CwebUrl,
            'Origin': $CwebUrl
        }
    });
    const resultAd3 = await responseAd3.json();
    adImg3.value = resultAd3.data[0];

    //广告4
    let url4 = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=snzxw_category_0004`
    const responseAd4 = await fetch(url4, {
        headers: {
            'Content-Type': 'application/json',
            'Userurl': $CwebUrl,
            'Origin': $CwebUrl
        }
    });
    const resultAd4 = await responseAd4.json();
    adImg4.value = resultAd4.data[0];
})
//3.广告 end ---------------------------------------->

//4.页面数据 start ---------------------------------------->
const pageData = ref([
    //示例：
    // {
    //     id: 1, 
    //     title: "", //该导航的标题
    //     data: [], //数据1
    //     data1: [], //数据2
    //     data2: [], //数据3
    //     data3: [], //数据4
    //     data4: [], //数据5
    //     category_id1: "",  //子导航id1
    //     category_id2: "", 
    //     category_id3: "",
    //     category_id4: "",
    //     title1: "", //子导航标题1
    //     title2: "",
    //     title3: "",
    //     title4: "",
    //     cid: "" //该导航的id
    // },
])

//4.1 获取所有导航
try {
    const navigateData = await requestDataPromise('/web/getWebsiteModelCategory', {
        method: 'GET',
        query: {
            'placeid': 1,
            'pid': routeId,
            'num': 8
        },
    });
    if (navigateData.code == 200) {
        // 遍历可用的导航池放到页面中
        for (let index in navigateData.data) {
            let data = {
                title: navigateData.data[index].name,
                cid: navigateData.data[index].category_id,
                children_count: navigateData.data[index].children_count,
                alias: navigateData.data[index].alias,
                aLIas_pinyin: targetSegment + "/" + navigateData.data[index].aLIas_pinyin,
                data: [],
                data1: [],
                data2: [],
                data3: [],
                data4: [],
                category_id1: "",
                category_id2: "",
                category_id3: "",
                category_id4: "",
                title1: "",
                title2: "",
                title3: "",
                title4: ""
            };
            if (navigateData.data[index].is_url == 1) {
                // 处理 URL 的逻辑
            } else {
                //每个页面最多8个模块
                pageData.value.push(data);
            }
        }
        //导航池加载完毕，开始申请模块数据
        let getJson = [
            { "parent": routeId + ",0,0", "child": pageData.value[0].cid + ",4,9" },//模块1 顶部没有标题的那个
            { "parent": routeId + ",0,0", "child": pageData.value[1].cid + ",3,11" },//模块2
            { "parent": routeId + ",0,0", "child": pageData.value[2].cid + ",2,7" },//模块3
            { "parent": routeId + ",0,0", "child": pageData.value[3].cid + ",0,8" },//模块4
            { "parent": routeId + ",0,0", "child": pageData.value[4].cid + ",1,0" },//模块5
            { "parent": routeId + ",0,0", "child": pageData.value[5].cid + ",1,6" },//模块6
            { "parent": routeId + ",0,0", "child": pageData.value[6].cid + ",1,6" },//模块7
            { "parent": routeId + ",0,0", "child": pageData.value[7].cid + ",1,7" },//模块8
        ]
        let jsonString = JSON.stringify(getJson);
        getPageAllData(jsonString);

    } else {
        console.log("错误：渲染8个模块环节出错，请检查是否存在没有数据的模块！")
    }
} catch (error) {
    console.log("错误：导航池渲染执行接口出错！请检查频道页渲染的模块数据是否完整！")
}


async function getPageAllData(jsonString) {
    const mkdata = await requestDataPromise('/web/getWebsiteAllArticle', {
        method: 'GET',
        query: {
            'id': jsonString
        },
    });

    if (mkdata.code == 200) {
        //模块1 顶部大图和列表
        pageData.value[0].data = mkdata.data[0].child.imgnum;
        pageData.value[0].data2 = mkdata.data[0].child.textnum;
        //模块2
        pageData.value[1].data3 = mkdata.data[1].child.textnum;
        for(let index in mkdata.data[1].child.imgnum){
            if(index<1){
                pageData.value[1].data.push(mkdata.data[1].child.imgnum[index]);
            }else{
                pageData.value[1].data2.push(mkdata.data[1].child.imgnum[index]);
            }
        }
        //模块3
        pageData.value[2].data = mkdata.data[2].child.imgnum;
        pageData.value[2].data2 = mkdata.data[2].child.textnum;
        //模块4
        pageData.value[3].data = mkdata.data[3].child.imgnum;
        pageData.value[3].data2 = mkdata.data[3].child.textnum;
        //模块5
        pageData.value[4].data = mkdata.data[4].child.imgnum;
        //模块6
        pageData.value[5].data = mkdata.data[5].child.imgnum;
        pageData.value[5].data2 = mkdata.data[5].child.textnum;
        //模块7
        pageData.value[6].data = mkdata.data[6].child.imgnum;
        pageData.value[6].data2 = mkdata.data[6].child.textnum;
        //模块8
        pageData.value[7].data = mkdata.data[7].child.imgnum;
        pageData.value[7].data2 = mkdata.data[7].child.textnum;
    } else {
        ElMessage.error(mkdata.message)
    }
}
//4.页面数据 end ---------------------------------------->

//5.设置seo信息 start---------------------------------------->
const setData = await requestDataPromise('/web/getWebsiteCategoryHead', {
    method: 'GET',
    query: {
        'catid': routeId
    },
});

if (setData.code == 200) {
    let seoTitle = setData.data.seo_title;
    let seoDescription = setData.data.seo_description;
    let seoKeywords = setData.data.seo_keywords;
    let seoSuffix = setData.data.suffix;
    let seoName = setData.data.website_name;

    useSeoMeta({
        title: seoTitle + "_" + seoSuffix,
        meta: [
            { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
            { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix, tagPriority: 10 }
        ]
    });
} else {
    console.log("设置频道页SEO出错！",setData.message)
}
//5.设置seo信息 end---------------------------------------->
</script>

<style lang="less" scoped>
@import '@/assets/css/class.less';
</style>